//
//  CZStatus.swift
//  weiBo
//
//  Created by apple on 16/5/14.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class CZStatus: NSObject {

    //  发微博时间
    var created_at: String?
    //  微博ID
    var id: Int64 = 0
    //  微博内容
    var text: String?
    //  微博来源
    var source: String?
    //  用户模型
    var user: CZUser?
    //  转发微博模型
    var retweeted_status: CZStatus?
    //  转发数
    var reposts_count: Int = 0
    //  评论数
    var comments_count: Int = 0
    //  表态数
    var attitudes_count: Int = 0
    //  图片数据
    var pic_urls: [CZStatusPictureInfo]?
    
    
    init(dict: [String : AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
    //为User的模型赋值
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
            guard let dic = value as? [String: AnyObject] else{
//                print("不是字典类型")
                return
            }
            user = CZUser(dict: dic)
        }else if key == "retweeted_status" {
            guard let dic = value as? [String : AnyObject] else {
                print("不是字典类型")
                return
            }
            retweeted_status = CZStatus(dict: dic)
        
        }else if key == "pic_urls" {
            guard let dicArray = value as? [[String : AnyObject]] else {
                return
            }
            //定义可变的模型数组
            var tempArray = [CZStatusPictureInfo]()
            for dic in dicArray {
                let model = CZStatusPictureInfo(dic: dic)
                tempArray.append(model)
            }
            pic_urls = tempArray
        
        }
        else{
            super.setValue(value, forKey: key)
        }
        
    }

}
